﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
namespace KabiManagementWeb.Controllers
{
    public class PenaltyController : Controller
    {
        KBManagementDataContext context = new KBManagementDataContext();
        
        //
        // GET: /Penalty/

        public ActionResult Index()
        {
            return View(context.Penalties);
        }

        //
        // GET: /Penalty/Details/5

        public ActionResult Details(int id)
        {
            
            return View(context.Penalties.Single(x=>x.ID.Equals(id)));
        }

        //
        // GET: /Penalty/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Penalty/Create

        [HttpPost]
        public ActionResult Create(Penalty collection)
        {
            try
            {
                // TODO: Add insert logic here
                collection.Status = true;
                context.Penalties.InsertOnSubmit(collection);
                context.SubmitChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Penalty/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(context.Penalties.Single(x => x.ID.Equals(id)));
        }

        //
        // POST: /Penalty/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Penalty collection)
        {
            try
            {
               var pe= context.Penalties.Single(x => x.ID.Equals(id));
                pe.Pe_Name=collection.Pe_Name;
                pe.Penalty_Details=collection.Penalty_Details;
                pe.ExceptSalary=collection.ExceptSalary;
                context.SubmitChanges();
                return RedirectToAction("Index");
             
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Penalty/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Penalty/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
